Skip to content

DynamoDB: BETWEEN no longer excludes an attribute value of 0 - #10193

Open
aryansk wants to merge 1 commit into
getmoto:masterfrom
aryansk:fix-dynamodb-between-zero
Open

DynamoDB: BETWEEN no longer excludes an attribute value of 0#10193
aryansk wants to merge 1 commit into
getmoto:masterfrom
aryansk:fix-dynamodb-between-zero

Conversation

@aryansk

@aryansk aryansk commented Aug 16, 2026

Copy link
Copy Markdown

Fixes #10186.

What

FuncBetween.expr() tested the compared attribute with bare Python truthiness (and attr). Since Decimal("0") is falsy, an item whose attribute value is exactly 0 failed a BETWEEN range even when 0 was inside it — e.g. price BETWEEN 0 AND 100 excluded price = 0 while including price = 5.

Why

The start and end operands already use a zero-safe check (start is not None and (isinstance(start, Decimal) or start)) for exactly this reason; the attribute operand was missed, so 0 behaves differently from any other number.

How

Give the attribute the same zero-safe check in all three branches:

attr_has_value = attr is not None and (isinstance(attr, Decimal) or attr)
if start_has_value and attr_has_value and end_has_value:
    return start <= attr <= end
...
elif start is None and attr_has_value and end_has_value:
    return attr <= end

Tests

New test_between_condition_includes_zero scans with price BETWEEN :lo AND :hi and asserts price = 0 is included (0..100 returns both items; -10..0 returns the zero item). Fails on main ({'five'} == {'five', 'zero'}), passes with the fix. Full test_dynamodb_condition_expressions.py suite passes; ruff findings on comparisons.py are pre-existing and untouched.

FuncBetween.expr() tested the attribute with bare truthiness, so a
Decimal('0') value failed the condition and was excluded even when it
fell inside the range. Apply the same zero-safe check start/end already
use. Regression test fails on main; condition-expression suite passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DynamoDB BETWEEN incorrectly excludes attribute value 0

1 participant